<template>
	<view class="content">
		<u-datetime-picker 
		:show="showStart" 
		v-model="timeStamp"
		closeOnClickOverlay
		mode="date" 
		@confirm="confirmStart"
		@cancel="showStart = false" 
		@close="showStart = false">
		</u-datetime-picker>
		<view class="section-0">
			<view class="section-bdoy">
				<view class="tab">
					<view @click="setCurIdx(idx, item.type)"
						:class="`item ${curIdx === idx ? 'item__active' : ''} ${curIdx + 1 === idx ? 'item__active_next' : ''}`"
						v-for="(item, idx) in tabList" :key="item.type">
						<view class="label">{{item.name}}</view>
						<view class="shape">
							<view class="shape-body"></view>
						</view>
						<view class="shape shape-mirrow">
							<view class="shape-body"></view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="section-1">
			<view class="section-body">
				<view class="item" v-for="item in board" :key="item.name" @click="goPage(item.path)">
					<view class="shape" v-if="item.right"></view>
					<view class="shape2" v-if="item.bottom"></view>
					<view class="top">{{item['name' + curIdx]}}</view>
					<view class="bottom">{{item.count}}<text>{{item.unit ? item.unit : '个'}}</text></view>
				</view>
			</view>
		</view>
		<view class="section-2">
			<view class="form">
				<view class="form-item">
					<view class="label">姓名</view>
					<view class="shape"></view>
					<view class="input">
						<u--input placeholderClass="input-placeholder" class="input-body" v-model="form.user_name">
						</u--input>
					</view>
				</view>
				<!-- <view class="form-item">
					<view class="label">项目名称</view>
					<view class="shape"></view>
					<view class="input">
						<u--input placeholderClass="input-placeholder" class="input-body" v-model="form.project_name">
						</u--input>
					</view>
				</view> -->
				<view class="form-item" v-if="curType === 4">
					<view class="label">时间</view>
					<view class="shape"></view>
					<view class="input">
						<div class="time-body" @click="showDate('start_time')">{{form.start_time}}</div>
						<div class="time-split">-</div>
						<div class="time-body" @click="showDate('end_time')">{{form.end_time}}</div>
					</view>
				</view>

				<view class="actions">
					<view class="action" @click="handleResetForm()">
						<text>重</text>
						<text>置</text>
					</view>
					<view class="action search" @click="handleSearch()">
						<text>查</text>
						<text>询</text>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="table-header">
					<view class="table-th name">姓名</view>
					<view class="table-total">
						<view class="table-th total">现场履职</view>
						<text>/</text>
						<view class="table-th total">问题</view>
						<text>/</text>
						<view class="table-th total">会议</view>
					</view>
				</view>
				<!-- <view class="result">
					<view class="left"><text class="iconfont icon-sousuo"></text>查询结果共 {{list.length}} 条</view>
					<view class="left" @click="handleExport()"><text class="iconfont icon-xiazai"></text>导出详情</view>
				</view> -->
				<scroll-view scroll-y="true" :class="`scroll-wrapper ${curType === 4 ? 'scroll-wrapper-small' : ''}`">
					<view class="item" v-for="(item, idx) in list" :key="item.id + '_' + idx">
						<view class="parent"
							@click="go(`/pages/statistics/comprehensive/duty/single/index?user_name=${item.user_name}&type=${curType}&total=${item.dk_total},${item.check_total},${item.meet_total}`)">
							<view class="name">
								{{item.user_name}}
							</view>
							<view class="action">
								<view class="iconfont icon-xiangyou1"></view>
							</view>
							<view class="count">
								<view class="bottom">
									<text>{{item.dk_total}}</text>/<text>{{item.check_total}}</text>/<text>{{item.meet_total}}</text>
								</view>
							</view>
							<!-- <view class="subname">{{item.project_name}}</view> -->
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	let doExport = require('@/src/utils/exportExcel.js');
	import {
		dutyAnalysisApi
	} from '@/api/duty.js';
	import {
		mapGetters,
		mapActions
	} from 'vuex';
	export default {
		data() {
			return {
				showStart: false,
				timeStamp: '',
				board: [
					{
						name0: '全部履职总次数',
						name1: '本日履职总次数',
						name2: '本周履职总次数',
						name3: '本月履职总次数',
						
						count: 0,
						right: true,
						bottom: true,
						unit: '次',
						path: '/pages/statistics/comprehensive/duty/total/index'
					},
					{
						name0: '全部发现问题',
						name1: '本日发现问题',
						name2: '本周发现问题',
						name3: '本月发现问题',
						
						count: 0,
						right: true,
						unit: '个',
						path: '/pages/statistics/comprehensive/duty/problem/index'
					},
					{
						name0: '全部会议',
						name1: '本日会议',
						name2: '本周会议',
						name3: '本月会议',
						
						count: 0,
						unit: '次',
						path: '/pages/statistics/comprehensive/duty/meeting/index'
					},
				],
				list: [],
				tabList: [
					{
						type: 4,
						name: '全部'
					},
					{
						type: 1,
						name: '日报'
					},
					{
						type: 2,
						name: '周报'
					},
					{
						type: 3,
						name: '月报'
					},
					
				],
				curIdx: 0,
				curType: 4,
				form: {
					user_name: '',
					start_time: '',
					end_time: ''
				}
			};
		},
		methods: {
			...mapActions({setParams: 'duty/setParams'}),
			handleExport() {
				let name = '履职记录'
				let arr = [
					[{
						content: '姓名',
						type: 'text',
						width: '200px',
						height: '25px',
						fontSize: '16px'
					}, {
						content: '项目',
						type: 'text',
						width: '200px',
						height: '25px',
						fontSize: '16px'
					}, {
						content: '打卡次数',
						color: 'blue',
						type: 'text',
						width: '200px',
						height: '25px',
						fontSize: '16px'
					}],
				];
				this.list.forEach(item => {
					let _arr = [{
						content: item.user_name,
						type: 'text',
						width: '400px',
						height: '40px',
						fontSize: '13px'
					},{
						content: item.project_name,
						type: 'text',
						width: '400px',
						height: '40px',
						fontSize: '13px'
					},{
						content: item.total,
						type: 'text',
						width: '400px',
						height: '40px',
						color: 'blue',
						fontSize: '13px'
					}]
					arr.push(_arr);
				})
				doExport(name, arr, (res) => {
					uni.openDocument({ filePath: '/storage/emulated/0'+res, success: function (res) {
 }
				   });
				})
			},
			handleResetForm() {
				for (let key in this.form) {
					this.form[key] = '';
				}
				this.setParams(this.form);
				this.fetchData();
			},
			handleSearch() {
				this.setParams(this.form);
				this.fetchData();
			},
			go(path) {
				uni.navigateTo({
					url: path
				})
			},
			goPage(path) {
				uni.navigateTo({
					url: path + '?type=' + this.curType
				})
			},
			setCurIdx(idx, type) {
				this.curIdx = idx;
				this.curType = type;
				console.log(idx, type);
				this.handleResetForm();
			},
			showDate(type) {
				this.timeType = type;
				this.showStart = true;
			},
			closeDate(type) {
				this.timeType = '';
				this.showStart = false;
			},
			formatDate(timeStamp) {
				const date = new Date(timeStamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				const Y = date.getFullYear() + '-';
				const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				const D = date.getDate();
				const h = date.getHours() + ':';
				const m = date.getMinutes() + ':';
				const s = date.getSeconds();
				return Y + M + D;
			},
			confirmStart(val) {
				const timeStamp = val.value;
				this.form[this.timeType] = this.formatDate(timeStamp);
				this.closeDate();
			},
			async fetchData() {
				uni.showLoading({
					title: '加载中...'
				});
				let params = {};
				for (let key in this.form) {
					if (this.form[key] != '') {
						params[key] = this.form[key];
					}
				}
				const {
					data
				} = await dutyAnalysisApi({
					type: this.curIdx,
					...params
				});
				uni.hideLoading();
				if (data.code === 1) {
					const res = data.data;
					this.board[0].count = res.tong_ji.total;
					// this.board[1].count = res.tong_ji.lz_times + '/' + res.tong_ji.lz_total;
					this.board[1].count = res.tong_ji.problem_total;
					this.board[2].count = res.tong_ji.meet_total;
					this.list = res.list;
				}
			}
		},
		onReady() {
			this.fetchData();
			this.timeStamp = (new Date()).valueOf();
		},
		onShow(){
			this.setCurIdx(1,1)
		},
		onNavigationBarButtonTap(res) {
			this.handleExport()
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #fff;
	}

	.section-0 {
		background-color: #2c5cff;

		.section-bdoy {
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			background-color: #2c5cff;
			overflow: hidden;

			.tab {
				width: 100%;
				height: 100rpx;
				@include clear();
				background-color: #10298a;

				.item {
					width: 25%;
					float: left;
					height: 100rpx;
					background-color: #10298a;
					position: relative;

					.label {
						width: 100%;
						float: left;
						position: relative;
						z-index: 10;
						box-sizing: border-box;
						text-align: center;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #87c6ff;
						line-height: 100rpx;
					}

					.time-picker {
						margin-top: 32rpx;
						float: left;
						display: inline-block;
						padding: 0 18rpx;
						height: 36rpx;
						border-radius: 17rpx;
						border: solid 1rpx #87c6ff;
						line-height: 36rpx;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: #87c6ff;
						margin-left: 20rpx;
					}

					.shape {
						z-index: 1;
						width: 50rpx;
						height: 50rpx;
						position: absolute;
						bottom: 0;
						left: -50rpx;
						background: #000;
						display: none;
						background-color: #1d33c6;
						overflow: hidden;

						.shape-body {
							width: 50rpx;
							height: 50rpx;
							background-color: #10298a;
							border-bottom-right-radius: 50rpx;
						}
					}

					.shape-mirrow {
						z-index: 1;
						left: 0;
						display: none;

						.shape-body {
							border-bottom-right-radius: 0rpx;
							border-bottom-left-radius: 50rpx;
						}
					}
				}

				.item__active {
					border-top-left-radius: 50rpx;
					border-top-right-radius: 50rpx;
					background-color: #1534ce;

					.label {
						color: #fff;
					}

					.shape {
						display: block;
					}

					.shape-mirrow {
						display: none;
					}
				}

				.item__active_next {
					border-bottom-right-radius: 50rpx;

					.shape {
						display: none;
					}

					.shape-mirrow {
						display: block;
					}
				}
			}

			.top-total {
				width: 100%;
				box-sizing: border-box;
				height: 88rpx;
				line-height: 88rpx;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				letter-spacing: 0rpx;
				color: #87c6ff;
				background: #1534ce;
				padding-left: 40rpx;
				padding-right: 40rpx;

				text {
					font-weight: bold;
					font-size: 58rpx;
					font-weight: normal;
					font-stretch: normal;
					line-height: 49rpx;
					letter-spacing: 0rpx;
					color: #ffffff;
				}
			}
		}

	}

	.section-2 {
		position: relative;
		height: 400rpx;
		top: -50rpx;
		z-index: 10;
		background-color: #fff;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;

		.list {
			box-shadow: 0rpx 10rpx 20rpx 0rpx rgba(0, 0, 0, 0.05) inset;
			width: 100%;
			box-sizing: border-box;
			padding-left: 40rpx;
			padding-right: 40rpx;
			.table-header{
				width: 100%;
				@include clear();
				padding-top: 10rpx;
				.table-th{
					font-size: 26rpx;
					color: #7f98ae;
					float: left;
					text-align: center;
					font-weight: bold;
				}
				.name{
					float: left;
				}
				.table-total{
					float: right;
					.table-th{
						min-width: 60rpx;
					}
					text{
						display: inline-block;
						font-size: 26rpx;
						float: left;
						opacity: 0;
					}
					margin-right: 32rpx;
				}
			}
			// border-top: 2rpx solid #d8e4f2;
			.scroll-wrapper{
				width: 100%;
				height: calc(100vh - 530rpx);
			}
			.scroll-wrapper-small{
				height: calc(100vh - 530rpx - 82rpx);
			}
			.result {
				padding-top: 30rpx;
				width: 100%;
				height: 60rpx;
				line-height: 60rpx;
				@include clear();

				.left {
					float: left;
					font-size: 26rpx;
					color: #0535d6;

					.iconfont {
						font-size: 26rpx;
						margin-right: 10rpx;
					}

					&:last-child {
						float: right;
					}
				}
			}

			.item {
				width: 100%;
				border-bottom: solid 2rpx #f2f2f0;
				
				.parent {
					width: 100%;
					@include clear();
					padding-top: 15rpx;
					padding-bottom: 20rpx;

					.name {
						width: 350rpx;
						height: 50rpx;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						line-height: 50rpx;
						letter-spacing: 2rpx;
						color: #3b3c40;
						text-overflow: ellipsis;
						overflow: hidden;
						white-space: nowrap;
						float: left;
					}

					.count {
						float: right;
						min-width: 46rpx;
						height: 50rpx;
						border-radius: 28rpx;
						line-height: 50rpx;
						text-align: center;
						font-size: 26rpx;
						font-weight: bold;
						color: #3b3c40;
						// margin-right: 40rpx;
						// text {
						// 	font-size: 16rpx;
						// }
						.bottom{
							@include font-normal();
							font-weight: normal;
							text{
								display: inline-block;
								min-width: 60rpx;
							}
						}
					}
					.action {
						float: right;
						width: 32rpx;
						height: 50rpx;
						line-height: 50rpx;
						text-align: center;
						color: #3b3c40;

						.iconfont {
							font-size: 30rpx;
						}
					}

					.subname {
						width: 100%;
						float: left;
						font-family: SourceHanSansCN-Regular;
						font-size: 16rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 2rpx;
						color: #7899b0;
					}
				}
			}
		}

		.actions {
			width: 100%;
			height: 50rpx;
			margin-top: 29rpx;
			padding-bottom: 40rpx;
			display: flex;
			justify-content: space-between;

			.action {
				width: 288rpx;
				height: 48rpx;
				background-color: #395cf5;
				border-radius: 20rpx;
				text-align: center;
				line-height: 48rpx;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				line-height: 48rpx;
				color: #ffffff;

				text {
					&:first-child {
						margin-right: 20rpx;
					}
				}
			}

			.search {
				background-color: #1534ce;
			}
		}

		.form {
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;

			.form-item {
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 34rpx;
				@include clear();

				.label {
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}

				.shape {
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}

				.input {
					float: left;
					width: calc(100% - 134rpx - 3rpx);

					.time-body {
						height: 48rpx;
						width: 45%;
						float: left;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.7);
						text-align: center;
						line-height: 48rpx;
					}

					.time-split {
						float: left;
						width: 10%;
						text-align: center;
						color: #1534ce;
						line-height: 44rpx;
					}

					.input-body {
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						line-height: 44rpx;
						padding: 0 !important;
						border: none;
						padding-left: 30rpx !important;
						padding-right: 30rpx !important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.7);
					}

					.input-placeholder {
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0, 0, 0, 0.5);
					}
				}
			}

			.size4 {
				.input {
					position: relative;

					.iconfont {
						position: absolute;
						right: 25rpx;
						top: 7rpx;
						font-size: 30rpx;
						color: #dad9df;
					}
				}
			}

			.size2 {
				.label {
					width: 77rpx;
				}

				.input {
					width: calc(100% - 77rpx - 3rpx);
				}
			}
		}
	}

	.section-1 {
		width: 100%;
		background-color: #1534ce;

		.section-body {
			width: 670rpx;
			margin-left: 40rpx;
			margin-right: 40rpx;
			padding-bottom: 50rpx;
			padding-top: 20rpx;
			background-color: #1534ce;
			background-size: cover;
			background-repeat: no-repeat;
			overflow: hidden;
			box-sizing: border-box;
			// box-shadow: 0rpx 15rpx 10rpx 0rpx rgba(0, 0, 0, 0.05) inset;

			.item {
				width: 33.33%;
				float: left;
				display: flex;
				flex-wrap: wrap;
				align-content: space-between;
				height: 100rpx;
				position: relative;
				padding-top: 20rpx;
				padding-bottom: 20rpx;

				.shape {
					width: 4rpx;
					height: 84rpx;
					background-image: linear-gradient(rgba(#3658f2, 0.3) 0%, #3658f2 30%, #3658f2 70%, rgba(#3658f2, 0.3) 100%, );
					position: absolute;
					right: 0;
					top: 28rpx;
				}

				.shape2 {
					height: 4rpx;
					width: 172rpx;
					background-image: linear-gradient(90deg, rgba(#3658f2, 0.3) 0%, #3658f2 30%, #3658f2 70%, rgba(#3658f2, 0.3) 100%, );
					position: absolute;
					left: 0;
					right: 0;
					margin: 0 auto;
					bottom: -2rpx;
				}

				.top {
					width: 100%;
					text-align: center;
					font-size: 16rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #95c4fa;
				}

				.bottom {
					width: 100%;
					text-align: center;
					font-size: 58rpx;
					font-weight: bold;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #ffde00;

					text {
						font-size: 26rpx;
						font-weight: normal;
						letter-spacing: 0rpx;
						color: #87c6ff;
					}
				}
			}
		}
	}
</style>
